Skip to content

Preprocessor symbols for nullable reference types: Define a single nullable context. #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 10, 2024

Conversation

BillWagner
Copy link
Member

@BillWagner BillWagner commented May 29, 2024

Fixes #1088

Alternative PR to #1108

This branch builds on the work in #1108. This is an alternative approach that defines a single nullable context. The nullable context has two properties: annotations and warnings that can be enabled or disabled separately.

The first commit ports in the text from dotnet#700 substantially without change. The only editorial change is to move the clause on "Nullable directives" in lexical-structure before the clause on Pragma directives.

In addition, it fixes build warnings
Remove an Xref to a section that's not in this PR.
Alternative PR to dotnet#1108.

This branch builds on the work in dotnet#1108. This is an alternative approach that defines a single `nullable` context. The nullable context has two properties: `annotations` and `warnings` that can be enabled or disabled separately.
@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label May 29, 2024
Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, personally I like this better than having multiple separate notional contexts.

Copy link
Contributor

@Nigel-Ecma Nigel-Ecma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of language fixes/clarifications required so it describes the same overall semantics as #1108.

@Nigel-Ecma
Copy link
Contributor

Yup, personally I like this better than having multiple separate notional contexts.

I probably agree (yes I'm hedging ;-)) – If a file starts with an enable/disable and never changes it makes little difference. However I can see that when nullable state is enabled & disabled at different points in a file having one context might make that semantic description simpler.

@jskeet
Copy link
Contributor

jskeet commented Jun 12, 2024

Example of something that might be hard to understand:

#nullable disable
string x = null;
string y = "";
#nullable enable
Console.WriteLine(x.ToString());
Console.WriteLine(y.ToString());

Should that give a warning for x.ToString()?

#1124 states: "However, the disabled context means the compiler does not track null state and does not issue nullable related warnings" - so that would suggest no warning.

However, (with .NET 8 SDK) it issues a warning:

warning CS8602: Dereference of a possibly null reference.

Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved but with changes as described.

This commit addresses all online feedback.
I listened to the June meeting. I updated a bit of text, and added Jon's example  from the conversation.
@BillWagner
Copy link
Member Author

I updated everything from the last meeting (both comments, and from the in-meeting discussion). This should be ready to merge @jskeet

We can discuss at the meeting, or merge before.

@jskeet
Copy link
Contributor

jskeet commented Jul 10, 2024

We can discuss at the meeting, or merge before.

Let's get a final review at the meeting just in case. It would be handy if everyone could review beforehand though.

Copy link
Contributor

@Nigel-Ecma Nigel-Ecma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few language issues.

I also do not think we should approve/merge this, it is one of a set and as the others are developed we might need to circle around to this or any of them. So we should leave it as "done for now", a well known Github state ;-)

@jskeet
Copy link
Contributor

jskeet commented Jul 10, 2024

I also do not think we should approve/merge this, it is one of a set and as the others are developed we might need to circle around to this or any of them. So we should leave it as "done for now", a well known Github state ;-)

This was discussed unfortunately in Nigel's absence due to connectivity issues. We agreed that it would be better to avoid having multiple PRs hanging around and getting stale - the spec is "always inconsistent" in a draft form, as it doesn't accurately describe any specific version of C#.

If Nigel wishes to convince us otherwise, we could always revert the commit and open another PR :)

We will dismiss Nigel's review in order to merge now.

@jskeet jskeet dismissed Nigel-Ecma’s stale review July 10, 2024 20:42

See comment starting "This was discussed unfortunately"

@BillWagner BillWagner merged commit 8fac1a4 into dotnet:draft-v8 Jul 10, 2024
8 checks passed
@BillWagner BillWagner deleted the single-nullable-context branch July 10, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting: discuss This issue should be discussed at the next TC49-TG2 meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Nullable Reference Types] Compiler directives for nullable reference types
4 participants